package cn.aiyuan;

import cn.aiyuan.domain.Purview;
import cn.aiyuan.domain.Rule;
import cn.aiyuan.domain.User;
import cn.hutool.core.collection.ListUtil;
import lombok.NonNull;
import lombok.SneakyThrows;
import lombok.val;
import lombok.var;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author wangyuan
 * @date 2021/7/8
 */
public class StreamTest {

    public static void main(String[] args) {

        List<Purview> p1 = ListUtil.of(new Purview("1"), new Purview("2"), new Purview("3"));
        List<Purview> p2 = ListUtil.of(new Purview("4"), new Purview("5"), new Purview("6"));
        List<Purview> p3 = ListUtil.of(new Purview("7"), new Purview("8"), new Purview("9"));
        Rule r1 = new Rule("r1", p1);
        Rule r2 = new Rule("r2", p2);
        User u1 = new User("u1", ListUtil.of(r1, r2));
        User u2 = new User("u2", ListUtil.of(new Rule("r3", p3),null));
        List<User> users = ListUtil.of(u2, u1);

        List<String> collect = users.stream()
                .map(User::getRules)
                .filter(Objects::nonNull)
                .flatMap(Collection::stream)
                .filter(Objects::nonNull)
                .map(Rule::getPurview)
                .flatMap(Collection::stream)
                .map(Purview::getName).collect(Collectors.toList());
        System.out.println(collect);

        System.out.println("sss".substring(2));
        var name = "name";
        var age = 18;
        var ff = 20.5F;
        var dd = 20.5D;
        var en = true;
        val name1 = "123";
        System.out.println(name);
        System.out.println(name1);
        test(null);
    }

    @SneakyThrows
    public static void test(@NonNull String name){
        System.out.println(name);
    }
}
